package com.seed.fileud.service;

import com.seed.fileud.Fileud;
import com.seed.fileud.FileudProperties;
import com.seed.fileud.enumeration.FileudType;
import com.seed.fileud.pojo.FileStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Map;

@Service
public class DefaultFileudService implements FileudService {
    private final FileudService fileudService;

    public DefaultFileudService(FileudProperties fileud) {
        Map<String, Object> config = fileud.getConfig();
        FileudType type = fileud.getType();
        switch (type) {
            case minio -> throw new RuntimeException("【minio】未实现");
            case aliyun -> throw new RuntimeException("【aliyun】未实现");
            default -> this.fileudService = new LocalFileudService(config);
        }
    }

    @Override
    public FileStatus validate(String bucket, String path, String hash, String fileName, Integer chunkCount) {
        return fileudService.validate(bucket, path, hash, fileName, chunkCount);
    }

    @Override
    public String uploadFile(String bucket, String path, String hash, MultipartFile multipartFile) {
        return fileudService.uploadFile(bucket, path, hash, multipartFile);
    }

    @Override
    public void uploadChunk(String bucket, String path, String hash, Integer chunkIndex, MultipartFile multipartFile) {
        fileudService.uploadChunk(bucket, path, hash, chunkIndex, multipartFile);
    }

    @Override
    public String merge(String bucket, String path, String hash, String fileName) {
        return fileudService.merge(bucket, path, hash, fileName);
    }

    @Override
    public void remove(String filePath) {
        fileudService.remove(filePath);
    }

    @Override
    public File file(String filePath) {
        return fileudService.file(filePath);
    }

    @Override
    public byte[] readFile(String filePath, Long offset, Long length) {
        return fileudService.readFile(filePath, offset, length);
    }
}
